#ifndef DOXYBLOCKS_H_INCLUDED
#define DOXYBLOCKS_H_INCLUDED

#include <cbplugin.h>
#include <M_Code_StyledTextCtrl.h>
#include <tinyxml.h>
#include "Config.h"

class ConfigPanel;
class DoxyBlocksLogger;

class DoxyBlocks : public M_Code_Plugin {
  public:
    enum eLogLevel {
      LOG_NORMAL,
      LOG_WARNING,
      LOG_ERROR
    };
    DoxyBlocks();
    virtual ~DoxyBlocks();
    virtual int Configure();
    virtual int GetConfigurationPriority() const { return 50; }
    virtual int GetConfigurationGroup() const { return cgEditor; }
    virtual cbConfigurationPanel* GetConfigurationPanel( wxWindow* parent );
    virtual cbConfigurationPanel* GetProjectConfigurationPanel( wxWindow* parent, M_Code_Project* project );
    virtual void BuildMenu( wxMenuBar* menuBar );
    virtual void BuildModuleMenu( const ModuleType type, wxMenu* menu, const FileTreeData* data = 0 );
    virtual bool BuildToolBar( wxToolBar* toolBar );
    void OnDialogueDone( ConfigPanel* pDlg );
  protected:
    virtual void OnAttach();
    virtual void OnRelease( bool appShutDown );
    void OnRunDoxywizard( wxCommandEvent & event );
    void OnBlockComment( wxCommandEvent & event );
    void OnLineComment( wxCommandEvent & event );
    void OnExtractProject( wxCommandEvent & event );
    void OnRunHTML( wxCommandEvent & event );
    void OnRunCHM( wxCommandEvent & event );
    void OnConfigure( wxCommandEvent & event );
    void OnReadPrefsTemplate( wxCommandEvent & event );
    void OnWritePrefsTemplate( wxCommandEvent & event );
  private:
    bool DoRunDoxywizard();
    void DoBlockComment();
    void DoLineComment();
    void DoExtractProject();
    void WriteConfigFiles( M_Code_Project *prj, wxString sPrjName, wxString sPrjPath, wxString sDoxygenDir, wxFileName fnDoxyfile, wxFileName fnDoxygenLog );
    int GenerateDocuments( M_Code_Project *prj );
    void AppendToLog( const wxString& sText, eLogLevel flag = LOG_NORMAL, bool bReturnFocus = true ) const;
    bool IsProjectOpen() const;
    wxString GetInputList( M_Code_Project *prj, wxFileName fnDoxyfile );
    void DoRunHTML();
    void DoRunCHM();
    void RunCompiledHelp( wxString sDocPath, wxString sPrjName );
    wxString GetDocPath() const;
    wxString GetProjectName();
    void GetBlockCommentStrings( int iBlockComment, wxString &sStartComment, wxString &sMidComment, wxString &sEndComment );
    void StartComment( cbStyledTextCtrl *control, int &iPos, int iBlockComment, wxString sStartComment, wxString sMidComment, wxString sTagBrief, wxString sIndent );
    void CommentFunction( cbStyledTextCtrl *control, int &iPos, wxString sMidComment, wxString sTagParam, wxString sTagReturn, wxString sIndent, wxString sParams, wxString sReturn,  wxString sFunction );
    void CommentFortran( cbStyledTextCtrl *control, int iLine, int &iPos, wxString sMidComment, wxString sTagParam, wxString sTagReturn, wxString sIndent );
    bool IsLanguageFortran( M_Code_Editor *cbEd );
    void AddCommentLine( cbStyledTextCtrl *control, int &iPos, wxString sText );
    wxString ProcessReturnString( wxString sReturn, wxString sFunction );
    void CheckForAutoVersioning();
    wxString GetAutoVersion();
    void OnProjectActivate( CodeBlocksEvent& event );
    void OnEditorOpen( CodeBlocksEvent& event );
    void OnEditorClose( CodeBlocksEvent& event );
    void OnUpdateUI( wxUpdateUIEvent& event );
    void OnTextURL( wxTextUrlEvent& event );
    void LoadSettings();
    void SaveSettings();
    wxString ValidateRelativePath( wxString path );
    void DoReadPrefsTemplate();
    void DoWritePrefsTemplate();
    wxToolBar *m_pToolbar;       //!< The plug-in toolbar.
    DoxyBlocksLogger *m_DoxyBlocksLog;  //!< The log tab in the message pane.
    int m_LogPageIndex;    //!< The index of the log tab.
    bool m_bAutoVersioning; //!< Whether Autoversioning is active for the current project.
    wxString m_sAutoVersion;    //!< The autoversion string - MAJOR.MINOR.BUILD.
    wxString m_sVersionHeader;  //!< The Autoversion header path for the current project.
    DoxyBlocksConfig *m_pConfig;
    DECLARE_EVENT_TABLE();
};

#endif
